package dbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MyConn extends DBI {
    Connection connection;
    private String url="jdbc:mysql://localhost:3306/mynew?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true";
    public MyConn(){
        //加载驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
    @Override
    public Connection openConn() throws SQLException {
        connection = DriverManager.getConnection(url, "root","123456");

        return connection;
    }

    @Override
    public void closeConn() throws SQLException {
        if (connection!=null&&!connection.isClosed()){
        connection.close();

        }
    }
    public static  void main(String [] args){
        MyConn myConn = new MyConn();
        try {
            Connection connection = myConn.openConn();
            System.out.println(connection.isClosed());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
